package com.example.index

import android.os.Bundle
import com.example.index.adapter.IndexItemAdapter
import com.example.index.extension.quickStartActivity
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration
import kotlinx.android.synthetic.main.activity_index.*

abstract class BaseIndexActivity : BaseActivity(), IndexItemAdapter.OnItemClickListener {


    protected val indexItems = arrayListOf<Pair<String, Class<*>>>()


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_index)
        val itemAdapter = IndexItemAdapter(getData(), this)
        itemAdapter.cornerMarker = true
        recyclerview.adapter = itemAdapter
        recyclerview.addItemDecoration(
            HorizontalDividerItemDecoration.Builder(this)
                .colorResId(R.color.divider_light)
                .size(5)
                .build()
        )
    }

    abstract fun getData(): List<String>

    open fun handleItemClick(index: Int, title: String) {
        quickStartActivity(indexItems[index].second)
    }

    override fun onItemClick(position: Int) {
        handleItemClick(index = position, title = getData()[position])
    }
}
